package com.example.service;

import com.example.dao.NxQuestionTypeInfoDao;
import com.example.entity.NxQuestionTypeInfo;
import com.example.vo.NxQuestionTypeInfoVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class NxQuestionTypeInfoService {

    @Resource
    private NxQuestionTypeInfoDao nxQuestionTypeInfoDao;

    public NxQuestionTypeInfo add(NxQuestionTypeInfo nxQuestionTypeInfo) {
        nxQuestionTypeInfoDao.insertSelective(nxQuestionTypeInfo);
        return nxQuestionTypeInfo;
    }

    public void delete(Long id) {
        nxQuestionTypeInfoDao.deleteByPrimaryKey(id);
    }

    public void update(NxQuestionTypeInfo nxQuestionTypeInfo) {
        nxQuestionTypeInfoDao.updateByPrimaryKeySelective(nxQuestionTypeInfo);
    }

    public NxQuestionTypeInfo findById(Long id) {
        return nxQuestionTypeInfoDao.selectByPrimaryKey(id);
    }

    public List<NxQuestionTypeInfoVo> findAll() {
        return nxQuestionTypeInfoDao.findByName("all");
    }

    public PageInfo<NxQuestionTypeInfoVo> findPage(String name, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        PageHelper.startPage(pageNum, pageSize);
        List<NxQuestionTypeInfoVo> all = findAllPage(request, name);
        return PageInfo.of(all);
    }

    public List<NxQuestionTypeInfoVo> findAllPage(HttpServletRequest request, String name) {
		return nxQuestionTypeInfoDao.findByName(name);
    }

}
